const express = require('express')
const router = express.Router()
const authMiddleware = require('../middleware/authMiddleware') // 引入 Token 验证中间件
const UsersControllers = require('../controllers/usersControllers')

// 不需要 Token 验证的路由
router.post('/register', UsersControllers.addNewUser) // 注册
router.get('/acc/:acc',UsersControllers.getUserByAccount) // 根据账号获取用户
router.post('/login', UsersControllers.login) // 登录

// 需要 Token 验证的路由
router.delete('/:id', authMiddleware, UsersControllers.delUserById) // 删除用户
router.put('/:id', authMiddleware, UsersControllers.updateUserById) // 更新用户
router.get('/', authMiddleware, UsersControllers.getAllUsers) // 获取所有用户
router.get('/id/:id', authMiddleware, UsersControllers.getUserById) // 根据 ID 获取用户
router.get('/layout', authMiddleware, UsersControllers.layout) // 退出登录

module.exports = router